package com.winchain.chainbill.bill.biz.report.service.impl;

import com.shell.bee.base.utils.StringUtil;
import com.shell.framework.utils.SysDateUtil;
import com.winchain.chainbill.bill.biz.report.dao.BizBoardDao;
import com.winchain.chainbill.bill.biz.report.service.BizBoardService;
import com.winchain.chainbill.bill.biz.report.vo.BizBoardQueryVo;
import com.winchain.chainbill.bill.biz.report.vo.BizBoardStatsVo;
import com.winchain.chainbill.bill.biz.send.vo.BillSnd;
import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("bizBoardService")
public class BizBoardServiceImpl implements BizBoardService {
	@Autowired
	private BizBoardDao bizBoardDao;

	public int countCustomerByGrpId(String grpId) {
		return this.bizBoardDao.countCustomerByGrpId(grpId, "E",
				new String[] { "ENTERPRISE", "SELF_EMPLOYED", "PERSONAL" });
	}

	public List<BizBoardStatsVo> selectCustomersForBoard(String grpId, String startDate, String endDate,
			String tagCodes) {
		String[] tcs = null;
		if (!StringUtil.emptyAndNull(tagCodes)) {
			tcs = tagCodes.split(",");
		}
		String startDateTime = SysDateUtil.parseDate(startDate, "yyyyMMdd", "yyyy-MM-dd") + " 00:00:00";
		String endDateTime = SysDateUtil.parseDate(endDate, "yyyyMMdd", "yyyy-MM-dd") + " 23:59:59";
		return this.bizBoardDao.selectCustomersForBoard(grpId, startDateTime, endDateTime, tcs);
	}

	public List<BizBoardQueryVo> selectCustomersForDisBoard(String grpId) {
		return this.bizBoardDao.selectCustomersForDisBoard(grpId);
	}

	public BigDecimal countSendAmts(String grpId) {
		return this.bizBoardDao.countSendAmts(grpId, "S005");
	}

	public List<BizBoardQueryVo> selectBillSndsByGroupId(String grpId) {
		return this.bizBoardDao.selectBillSndsByGroupId(grpId, "S005");
	}

	public List<BillSnd> selectNotGrouByBillSndsByGroupId(String grpId) {
		return this.bizBoardDao.selectNotGrouByBillSndsByGroupId(grpId, "S005");
	}

	public BigDecimal countTransferAmts(String grpId) {
		return this.bizBoardDao.countTransferAmts(grpId, "S005", new String[] { "-2", "2" });
	}

	public List<BizBoardQueryVo> selectBillXfesByGroupId(String grpId) {
		return this.bizBoardDao.selectBillXfesByGroupId(grpId, "S005", new String[] { "-2", "2" });
	}

	public Integer countSplitXfeBillByGroupId(String grpId) {
		return this.bizBoardDao.countSplitXfeBillByGroupId(grpId);
	}

	public Integer countFullXfeBillByGroupId(String grpId) {
		return this.bizBoardDao.countFullXfeBillByGroupId(grpId);
	}

	public BigDecimal countDctAmts(String grpId) {
		return this.bizBoardDao.countDctAmts(grpId, new String[] { "2", "3", "1" });
	}

	public List<BizBoardQueryVo> selectDctsForDisBoard(String grpId) {
		return this.bizBoardDao.selectDctsForDisBoard(grpId, new String[] { "2", "3", "1" });
	}

	public List<BizBoardStatsVo> querySendBillsForBoard(String grpId, String startDate, String endDate,
			String buyerIds) {
		String[] bids = null;
		if (!StringUtil.emptyAndNull(buyerIds)) {
			bids = buyerIds.split(",");
		}
		return this.bizBoardDao.querySendBillsForBoard(grpId, startDate, endDate, bids);
	}

	public List<BizBoardStatsVo> queryXfeBillsForBoard(String grpId, String startDate, String endDate,
			String buyerIds) {
		String[] bids = null;
		if (!StringUtil.emptyAndNull(buyerIds)) {
			bids = buyerIds.split(",");
		}
		return this.bizBoardDao.queryXfeBillsForBoard(grpId, startDate, endDate, bids);
	}

	public List<BizBoardStatsVo> queryDctBillsForBoard(String grpId, String startDate, String endDate,
			String sellerIds) {
		String[] sids = null;
		if (!StringUtil.emptyAndNull(sellerIds)) {
			sids = sellerIds.split(",");
		}
		return this.bizBoardDao.queryDctBillsForBoard(grpId, startDate, endDate, sids);
	}

	public List<BizBoardStatsVo> queryRpurBillsForBoard(String grpId, String startDate, String endDate) {
		return this.bizBoardDao.queryRpurBillsForBoard(grpId, startDate, endDate);
	}
}
